package com.tea.controller;

import com.tea.Model.dto.CartAddDTO;
import com.tea.Model.dto.CartUpdateDTO;
import com.tea.Model.vo.CartVO;
import com.tea.service.CartService;
import com.tea.utils.Result;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {

    @Resource
    private CartService cartService;

    @PostMapping("/add")
    public Result<Void> add(@RequestBody CartAddDTO dto) {
        cartService.addToCart(dto);
        return Result.success();
    }


    @GetMapping("/list")
    public Result<List<CartVO>> list() {
        List<CartVO> cartList = cartService.getCartList();
        return Result.success(cartList);
    }

    @PostMapping("/update")
    public Result<Void> update(@RequestBody CartUpdateDTO dto) {
        cartService.updateQuantity(dto);
        return Result.success();
    }

    @DeleteMapping("/delete")
    public Result<Void> delete(@RequestBody List<Long> ids) {
        cartService.removeByIds(ids);
        return Result.success();
    }
}